home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / RCS / spriteKbd.c,v < prev    next >
Encoding:
Text File  |  1989-10-13  |  34.8 KB  |  1,357 lines

  1. head     5.4;
  2. branch   ;
  3. access   ;
  4. symbols  beta4:5.0;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 5.4
  10. date     88.10.01.10.39.05;  author ouster;  state Exp;
  11. branches ;
  12. next     5.3;
  13.  
  14. 5.3
  15. date     88.09.15.16.47.44;  author ouster;  state Exp;
  16. branches ;
  17. next     5.2;
  18.  
  19. 5.2
  20. date     88.09.15.16.31.16;  author ouster;  state Exp;
  21. branches ;
  22. next     5.1;
  23.  
  24. 5.1
  25. date     88.03.27.21.17.17;  author deboor;  state Exp;
  26. branches ;
  27. next     5.0;
  28.  
  29. 5.0
  30. date     87.09.11.11.26.12;  author deboor;  state Exp;
  31. branches ;
  32. next     1.5;
  33.  
  34. 1.5
  35. date     87.08.21.20.35.02;  author deboor;  state Exp;
  36. branches ;
  37. next     1.4;
  38.  
  39. 1.4
  40. date     87.06.20.19.56.46;  author deboor;  state Exp;
  41. branches ;
  42. next     1.3;
  43.  
  44. 1.3
  45. date     87.06.17.17.18.20;  author deboor;  state Exp;
  46. branches ;
  47. next     1.2;
  48.  
  49. 1.2
  50. date     87.06.17.16.16.21;  author deboor;  state Exp;
  51. branches ;
  52. next     1.1;
  53.  
  54. 1.1
  55. date     87.06.16.12.21.13;  author deboor;  state Exp;
  56. branches ;
  57. next     ;
  58.  
  59.  
  60. desc
  61. @keyboard interface
  62. @
  63.  
  64.  
  65. 5.4
  66. log
  67. @Back-fit Adam's fixes to autorepeat (they got made after I copied
  68. this file).
  69. @
  70. text
  71. @/*-
  72.  * spriteKbd.c --
  73.  *    Functions for retrieving data from a keyboard.
  74.  *
  75.  * Copyright (c) 1987 by the Regents of the University of California
  76.  *
  77.  * Permission to use, copy, modify, and distribute this
  78.  * software and its documentation for any purpose and without
  79.  * fee is hereby granted, provided that the above copyright
  80.  * notice appear in all copies.  The University of California
  81.  * makes no representations about the suitability of this
  82.  * software for any purpose.  It is provided "as is" without
  83.  * express or implied warranty.
  84.  *
  85.  *
  86.  */
  87. #ifndef lint
  88. static char rcsid[] =
  89.     "$Header: spriteKbd.c,v 5.3 88/09/15 16:47:44 ouster Exp $ SPRITE (Berkeley)";
  90. #endif lint
  91.  
  92. #define Time SpriteTime
  93. #include <fs.h>
  94. #undef Time
  95.  
  96. #define NEED_EVENTS
  97. #include    "spriteddx.h"
  98.  
  99. #include    <bit.h>
  100.  
  101. #include    <errno.h>
  102. #include    <fcntl.h>
  103. #include    <sys/file.h>
  104. #include    <sys/time.h>
  105.  
  106. #include    "keysym.h"
  107.  
  108. #define VKEY_UP          0x80
  109. #define VKEY_REPEAT    0x40
  110. #define VKEY_DOWN     0
  111.  
  112. #define MIN_KEYCODE    8       /* Keycode below which we may not transmit */
  113.  
  114. /*
  115.  * These constants are for Sun 2 and 3 keyboards only
  116.  */
  117. #define KBD_RESET    '\1'
  118. #define KBD_BELL_ON    '\2'
  119. #define KBD_BELL_OFF    '\3'
  120. #define KBD_CLICK_ON    '\12'
  121. #define KBD_CLICK_OFF    '\13'
  122.  
  123. static void       spriteBell();
  124. static void       spriteKbdCtrl();
  125. static Dev_KbdEvent *spriteKbdGetEvents();
  126. static void       spriteKbdProcessEvent();
  127. static void       spriteKbdDoneEvents();
  128.  
  129. /*
  130.  * Auto-repeat stuff.
  131.  */
  132. static enum {
  133.     REPEAT_LONG,        /* Start repeat with long timeout */
  134.     REPEAT_SHORT,        /* Start repeat with short timeout */
  135.     REPEAT_TIMEOUT,        /* In the middle of a timeout */
  136.     REPEAT_PENDING,        /* Repeat should be taken next */
  137.     REPEAT_NONE              /* No repeat should happen */
  138. }                  repeatPhase = REPEAT_NONE;
  139.  
  140. static Dev_KbdEvent    repeatEvent;    /* Event that will be repeated */
  141. static SpriteTime     repeatTimeout;    /* Timeout to use for repeating */
  142. static unsigned int    repeatDelta;    /* Timeout length (ms) */
  143. #define REPEAT_LONG_TIMEOUT    500         /* Ms delay to begin repeat */
  144. #define REPEAT_SHORT_TIMEOUT    10         /* Ms delay to continue repeat */
  145.  
  146. static KbPrivRec      sysKbPriv = {
  147.     -1,                /* Type of keyboard */
  148.     -1,                /* Descriptor open to device */
  149.     spriteKbdGetEvents,        /* Function to read events */
  150.     spriteKbdProcessEvent,    /* Function to process an event */
  151.     spriteKbdDoneEvents,    /* Function called when all events */
  152.                 /* have been handled. */
  153.     0,                          /* Keycode offset */
  154.     &defaultKeyboardControl,    /* Current keyboard control */     
  155.     (pointer)NULL,            /* Private to keyboard (nothing needed) */
  156. };
  157.  
  158.  
  159. /*
  160.  *    XXX - Its not clear what to map these to for now.
  161.  *    keysyms.h doesn't define enough function key names.
  162.  */
  163.  
  164. #ifndef XK_L1
  165. #define    XK_L1    XK_Cancel
  166. #define    XK_L2    XK_Redo
  167. #define    XK_L3    XK_Menu
  168. #define    XK_L4    XK_Undo
  169. #define    XK_L5    XK_Insert
  170. #define    XK_L6    XK_Select
  171. #define    XK_L7    XK_Execute
  172. #define    XK_L8    XK_Print
  173. #define    XK_L9    XK_Find
  174. #define    XK_L10    XK_Help
  175. #define    XK_R1    NoSymbol
  176. #define    XK_R2    NoSymbol
  177. #define    XK_R3    NoSymbol
  178. #define    XK_R4    NoSymbol
  179. #define    XK_R5    NoSymbol
  180. #define    XK_R6    NoSymbol
  181. #define    XK_R7    NoSymbol
  182. #define    XK_R8    XK_Up
  183. #define    XK_R9    NoSymbol
  184. #define    XK_R10    XK_Left
  185. #define    XK_R11    XK_Home
  186. #define    XK_R12    XK_Right
  187. #define    XK_R13    NoSymbol
  188. #define    XK_R14    XK_Down
  189. #define    XK_R15    NoSymbol
  190. #endif
  191.  
  192. static KeySym sunKbdMap[] = {
  193.     XK_L1,        NoSymbol,        /* 0x01 */
  194.     NoSymbol,    NoSymbol,        /* 0x02 */
  195.     XK_L2,        NoSymbol,        /* 0x03 */
  196.     NoSymbol,    NoSymbol,        /* 0x04 */
  197.     XK_F1,        NoSymbol,        /* 0x05 */
  198.     XK_F2,        NoSymbol,        /* 0x06 */
  199.     NoSymbol,    NoSymbol,        /* 0x07 */
  200.     XK_F3,        NoSymbol,        /* 0x08 */
  201.     NoSymbol,    NoSymbol,        /* 0x09 */
  202.     XK_F4,        NoSymbol,        /* 0x0a */
  203.     NoSymbol,    NoSymbol,        /* 0x0b */
  204.     XK_F5,        NoSymbol,        /* 0x0c */
  205.     NoSymbol,    NoSymbol,        /* 0x0d */
  206.     XK_F6,        NoSymbol,        /* 0x0e */
  207.     NoSymbol,    NoSymbol,        /* 0x0f */
  208.     XK_F7,        NoSymbol,        /* 0x10 */
  209.     XK_F8,        NoSymbol,        /* 0x11 */
  210.     XK_F9,        NoSymbol,        /* 0x12 */
  211.     XK_Break,    NoSymbol,        /* 0x13 */
  212.     NoSymbol,    NoSymbol,        /* 0x14 */
  213.     XK_R1,        NoSymbol,        /* 0x15 */
  214.     XK_R2,        NoSymbol,        /* 0x16 */
  215.     XK_R3,        NoSymbol,        /* 0x17 */
  216.     NoSymbol,    NoSymbol,        /* 0x18 */
  217.     XK_L3,        NoSymbol,        /* 0x19 */
  218.     XK_L4,        NoSymbol,        /* 0x1a */
  219.     NoSymbol,    NoSymbol,        /* 0x1b */
  220.     NoSymbol,    NoSymbol,        /* 0x1c */
  221.     XK_Escape,    NoSymbol,        /* 0x1d */
  222.     XK_1,        XK_exclam,        /* 0x1e */
  223.     XK_2,        XK_at,            /* 0x1f */
  224.     XK_3,        XK_numbersign,        /* 0x20 */
  225.     XK_4,        XK_dollar,        /* 0x21 */
  226.     XK_5,        XK_percent,        /* 0x22 */
  227.     XK_6,        XK_asciicircum,        /* 0x23 */
  228.     XK_7,        XK_ampersand,        /* 0x24 */
  229.     XK_8,        XK_asterisk,        /* 0x25 */
  230.     XK_9,        XK_parenleft,        /* 0x26 */
  231.     XK_0,        XK_parenright,        /* 0x27 */
  232.     XK_minus,    XK_underscore,        /* 0x28 */
  233.     XK_equal,    XK_plus,        /* 0x29 */
  234.     XK_quoteleft,    XK_asciitilde,        /* 0x2a */
  235.     XK_BackSpace,    NoSymbol,        /* 0x2b */
  236.     NoSymbol,    NoSymbol,        /* 0x2c */
  237.     XK_R4,        NoSymbol,        /* 0x2d */
  238.     XK_R5,        NoSymbol,        /* 0x2e */
  239.     XK_R6,        NoSymbol,        /* 0x2f */
  240.     NoSymbol,    NoSymbol,        /* 0x30 */
  241.     XK_L5,        NoSymbol,        /* 0x31 */
  242.     NoSymbol,    NoSymbol,        /* 0x32 */
  243.     XK_L6,        NoSymbol,        /* 0x33 */
  244.     NoSymbol,    NoSymbol,        /* 0x34 */
  245.     XK_Tab,        NoSymbol,        /* 0x35 */
  246.     XK_Q,        NoSymbol,        /* 0x36 */
  247.     XK_W,        NoSymbol,        /* 0x37 */
  248.     XK_E,        NoSymbol,        /* 0x38 */
  249.     XK_R,        NoSymbol,        /* 0x39 */
  250.     XK_T,        NoSymbol,        /* 0x3a */
  251.     XK_Y,        NoSymbol,        /* 0x3b */
  252.     XK_U,        NoSymbol,        /* 0x3c */
  253.     XK_I,        NoSymbol,        /* 0x3d */
  254.     XK_O,        NoSymbol,        /* 0x3e */
  255.     XK_P,        NoSymbol,        /* 0x3f */
  256.     XK_bracketleft,    XK_braceleft,        /* 0x40 */
  257.     XK_bracketright,    XK_braceright,    /* 0x41 */
  258.     XK_Delete,    NoSymbol,        /* 0x42 */
  259.     NoSymbol,    NoSymbol,        /* 0x43 */
  260.     XK_R7,        NoSymbol,        /* 0x44 */
  261.     XK_Up,        XK_R8,            /* 0x45 */
  262.     XK_R9,        NoSymbol,        /* 0x46 */
  263.     NoSymbol,    NoSymbol,        /* 0x47 */
  264.     XK_L7,        NoSymbol,        /* 0x48 */
  265.     XK_L8,        NoSymbol,        /* 0x49 */
  266.     NoSymbol,    NoSymbol,        /* 0x4a */
  267.     NoSymbol,    NoSymbol,        /* 0x4b */
  268.     XK_Control_L,    NoSymbol,        /* 0x4c */
  269.     XK_A,        NoSymbol,        /* 0x4d */
  270.     XK_S,        NoSymbol,        /* 0x4e */
  271.     XK_D,        NoSymbol,        /* 0x4f */
  272.     XK_F,        NoSymbol,        /* 0x50 */
  273.     XK_G,        NoSymbol,        /* 0x51 */
  274.     XK_H,        NoSymbol,        /* 0x52 */
  275.     XK_J,        NoSymbol,        /* 0x53 */
  276.     XK_K,        NoSymbol,        /* 0x54 */
  277.     XK_L,        NoSymbol,        /* 0x55 */
  278.     XK_semicolon,    XK_colon,        /* 0x56 */
  279.     XK_quoteright,    XK_quotedbl,        /* 0x57 */
  280.     XK_backslash,    XK_bar,            /* 0x58 */
  281.     XK_Return,    NoSymbol,        /* 0x59 */
  282.     NoSymbol,    NoSymbol,        /* 0x5a */
  283.     XK_Left,    XK_R10,            /* 0x5b */
  284.     XK_R11,        NoSymbol,        /* 0x5c */
  285.     XK_Right,    NoSymbol,        /* 0x5d */
  286.     NoSymbol,    NoSymbol,        /* 0x5e */
  287.     XK_L9,        NoSymbol,        /* 0x5f */
  288.     NoSymbol,    NoSymbol,        /* 0x60 */
  289.     XK_L10,        NoSymbol,        /* 0x61 */
  290.     NoSymbol,    NoSymbol,        /* 0x62 */
  291.     XK_Shift_L,    NoSymbol,        /* 0x63 */
  292.     XK_Z,        NoSymbol,        /* 0x64 */
  293.     XK_X,        NoSymbol,        /* 0x65 */
  294.     XK_C,        NoSymbol,        /* 0x66 */
  295.     XK_V,        NoSymbol,        /* 0x67 */
  296.     XK_B,        NoSymbol,        /* 0x68 */
  297.     XK_N,        NoSymbol,        /* 0x69 */
  298.     XK_M,        NoSymbol,        /* 0x6a */
  299.     XK_comma,    XK_less,        /* 0x6b */
  300.     XK_period,    XK_greater,        /* 0x6c */
  301.     XK_slash,    XK_question,        /* 0x6d */
  302.     XK_Shift_R,    NoSymbol,        /* 0x6e */
  303.     XK_Linefeed,    NoSymbol,        /* 0x6f */
  304.     XK_R13,        NoSymbol,        /* 0x70 */
  305.     XK_Down,    XK_R14,            /* 0x71 */
  306.     XK_R15,        NoSymbol,        /* 0x72 */
  307.     NoSymbol,    NoSymbol,        /* 0x73 */
  308.     NoSymbol,    NoSymbol,        /* 0x74 */
  309.     NoSymbol,    NoSymbol,        /* 0x75 */
  310.     NoSymbol,    NoSymbol,        /* 0x76 */
  311.     XK_Caps_Lock,    NoSymbol,        /* 0x77 */
  312.     XK_Meta_L,    NoSymbol,        /* 0x78 */
  313.     XK_space,    NoSymbol,        /* 0x79 */
  314.     XK_Meta_R,    NoSymbol,        /* 0x7a */
  315.     NoSymbol,    NoSymbol,        /* 0x7b */
  316.     NoSymbol,    NoSymbol,        /* 0x7c */
  317.     NoSymbol,    NoSymbol,        /* 0x7d */
  318.     NoSymbol,    NoSymbol,        /* 0x7e */
  319.     NoSymbol,    NoSymbol,        /* 0x7f */
  320. };
  321.  
  322. static KeySymsRec sunMapDesc = {
  323. /*  map        minKeyCode  maxKeyCode  width */
  324.     sunKbdMap,      1,        0x7a,    2
  325. };
  326.  
  327. #define    cT    (ControlMask)
  328. #define    sH    (ShiftMask)
  329. #define    lK    (LockMask)
  330. #define    mT    (Mod1Mask)
  331. static CARD8 sunModMap[MAP_LENGTH] = {
  332.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 00-0f */
  333.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 10-1f */
  334.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 20-2f */
  335.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 30-3f */
  336.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 40-4f */
  337.     0,  0,  0,  cT, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 50-5f */
  338.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  sH, 0,  0,  0,  0,  0, /* 60-6f */
  339.     0,  0,  0,  0,  0,  sH, 0,  0,  0,  0,  0,  0,  0,  0,  lK, mT,/* 70-7f */
  340.     0,  mT, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 80-8f */
  341.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* 90-9f */
  342.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* a0-af */
  343.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* b0-bf */
  344.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* c0-cf */
  345.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* d0-df */
  346.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* e0-ef */
  347.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, /* f0-ff */
  348. };
  349.  
  350.  
  351. /*-
  352.  *-----------------------------------------------------------------------
  353.  * spriteKbdProc --
  354.  *    Handle the initialization, etc. of a keyboard.
  355.  *
  356.  * Results:
  357.  *    None.
  358.  *
  359.  * Side Effects:
  360.  *    None.
  361.  *
  362.  *-----------------------------------------------------------------------
  363.  */
  364. /*ARGSUSED*/
  365. int
  366. spriteKbdProc (pKeyboard, what, argc, argv)
  367.     DevicePtr      pKeyboard;    /* Keyboard to manipulate */
  368.     int              what;            /* What to do to it */
  369.     int              argc;
  370.     char          **argv;
  371. {
  372.     register int  fd;
  373.     int          tmp;
  374.     KbPrivPtr      pPriv;
  375.     int              i;
  376.     char      reset = KBD_RESET;
  377.     BYTE          map[MAP_LENGTH];
  378.  
  379.     switch (what) {
  380.     case DEVICE_INIT:
  381.         if (pKeyboard != LookupKeyboardDevice()) {
  382.         ErrorF ("Cannot open non-system keyboard");
  383.         return (!Success);
  384.         }
  385.         /*
  386.          * First open and find the current state of the keyboard
  387.          * If we are reinitializing, then turn the device OFF first.
  388.          */
  389.         if (sysKbPriv.fd >= 0) {
  390.         fd = sysKbPriv.fd;
  391.         } else {
  392.             ReturnStatus status;
  393.  
  394.         status = Fs_Open("/dev/Xevent",
  395.             FS_NON_BLOCKING|FS_READ|FS_WRITE, 0, &sysKbPriv.fd);
  396.             if (status != 0) {
  397.             errno = Compat_MapCode(status);
  398.             Error ("Opening /dev/Xevent");
  399.             return (!Success);
  400.         }
  401.         fd = sysKbPriv.fd;
  402.         }
  403.  
  404.         /*
  405.          * Perform final initialization of the system private keyboard
  406.          * structure and fill in various slots in the device record
  407.          * itself which couldn't be filled in before.
  408.          */
  409.         pKeyboard->devicePrivate = (pointer)&sysKbPriv;
  410.  
  411.         pKeyboard->on = FALSE;
  412.         /*
  413.          * Make sure keycodes we send out are >= MIN_KEYCODE
  414.          */
  415.          if (sunMapDesc.minKeyCode < MIN_KEYCODE) {
  416.          int    offset;
  417.  
  418.          offset = MIN_KEYCODE - sunMapDesc.minKeyCode;
  419.          sunMapDesc.minKeyCode += offset;
  420.          sunMapDesc.maxKeyCode += offset;
  421.          sysKbPriv.offset = offset;
  422.          }
  423.  
  424.         InitKeyboardDeviceStruct(pKeyboard, &sunMapDesc, sunModMap,
  425.                      spriteBell, spriteKbdCtrl);
  426.  
  427.         /*
  428.          * Reset keyboard to avoid spurious events (No!  don't do now:
  429.          * doesn't work in Sprite).
  430.         (void) write(fd, &reset, 1);
  431.          */
  432.         break;
  433.     case DEVICE_ON:
  434.         pKeyboard->on = TRUE;
  435.         AddEnabledDevice(((KbPrivPtr)pKeyboard->devicePrivate)->fd);
  436.         /*
  437.          * Initialize auto-repeat.
  438.          */
  439.         repeatPhase = REPEAT_NONE;
  440.         break;
  441.     case DEVICE_CLOSE:
  442.     case DEVICE_OFF:
  443.         pKeyboard->on = FALSE;
  444.         RemoveEnabledDevice(((KbPrivPtr)pKeyboard->devicePrivate)->fd);
  445.         /*
  446.          * Make sure auto-repeat doesn't generate events now that the
  447.          * keyboard is off.
  448.          */
  449.         repeatPhase = REPEAT_NONE;
  450.         break;
  451.     }
  452.     return (Success);
  453. }
  454.  
  455. /*-
  456.  *-----------------------------------------------------------------------
  457.  * spriteBell --
  458.  *    Ring the terminal/keyboard bell
  459.  *
  460.  * Results:
  461.  *    None.
  462.  *
  463.  * Side Effects:
  464.  *    None, really...
  465.  *
  466.  *-----------------------------------------------------------------------
  467.  */
  468. static void
  469. spriteBell (loudness, pKeyboard)
  470.     int              loudness;        /* Percentage of full volume */
  471.     DevicePtr      pKeyboard;        /* Keyboard to ring */
  472. {
  473.     KbPrivPtr        pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  474.     char        kbdCmd;
  475.     struct timeval    sleepTime;
  476.  
  477.     if (loudness == 0) {
  478.     return;
  479.     }
  480.  
  481.     kbdCmd = KBD_BELL_ON;
  482.     (void) write(pPriv->fd, &kbdCmd, 1);
  483.  
  484.     sleepTime.tv_usec = pPriv->ctrl->bell_duration * 1000;
  485.     sleepTime.tv_sec = 0;
  486.     while (sleepTime.tv_usec >= 1000000) {
  487.     sleepTime.tv_sec += 1;
  488.     sleepTime.tv_usec -= 1000000;
  489.     }
  490.     (void) select(0, (int *) 0, (int *) 0, (int *) 0, &sleepTime);
  491.  
  492.     kbdCmd = KBD_BELL_OFF;
  493.     (void) write(pPriv->fd, &kbdCmd, 1);
  494. }
  495.  
  496. /*-
  497.  *-----------------------------------------------------------------------
  498.  * spriteKbdCtrl --
  499.  *    Alter some of the keyboard control parameters
  500.  *
  501.  * Results:
  502.  *    None.
  503.  *
  504.  * Side Effects:
  505.  *    Some...
  506.  *
  507.  *-----------------------------------------------------------------------
  508.  */
  509. static void
  510. spriteKbdCtrl (pKeyboard, ctrl)
  511.     DevicePtr      pKeyboard;        /* Keyboard to alter */
  512.     KeybdCtrl      *ctrl;            /* New control info */
  513. {
  514.     KbPrivPtr      pPriv;
  515.     char      kbCmd;
  516.  
  517.     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  518.  
  519.     pPriv->ctrl = ctrl;
  520.     if (ctrl->click) {
  521.     kbCmd = KBD_CLICK_ON;
  522.     } else {
  523.     kbCmd = KBD_CLICK_OFF;
  524.     }
  525.  
  526.     (void) write(pPriv->fd, &kbCmd, 1);
  527.  
  528.     if (!ctrl->autoRepeat) {
  529.     repeatPhase = REPEAT_NONE;
  530.     }
  531. }
  532.  
  533. /*-
  534.  *-----------------------------------------------------------------------
  535.  * spriteKbdGetEvents --
  536.  *    Return the events waiting in the wings for the given keyboard.
  537.  *
  538.  * Results:
  539.  *    A pointer to an array of Firm_events or (Firm_event *)0 if no events
  540.  *    The number of events contained in the array.
  541.  *
  542.  * Side Effects:
  543.  *    None.
  544.  *-----------------------------------------------------------------------
  545.  */
  546. static Dev_KbdEvent *
  547. spriteKbdGetEvents (pKeyboard, pNumEvents)
  548.     DevicePtr      pKeyboard;        /* Keyboard to read */
  549.     int              *pNumEvents;        /* Place to return number of events */
  550. {
  551.     static Dev_KbdEvent    evBuf[MAXEVENTS];   /* Buffer for input events */
  552.  
  553.     if (repeatPhase == REPEAT_PENDING) {
  554.     /*
  555.      * This will only have been set if no streams were really ready, thus
  556.      * there are no events to read from Xevent.
  557.      */
  558.     repeatEvent.keyUp = VKEY_REPEAT;
  559.     repeatEvent.time += repeatDelta / 2;
  560.     evBuf[0] = repeatEvent;
  561.  
  562.     repeatEvent.keyUp = VKEY_DOWN;
  563.     repeatEvent.time += repeatDelta / 2;
  564.     evBuf[1] = repeatEvent;
  565.  
  566.     *pNumEvents = 2;
  567.  
  568.     repeatPhase = REPEAT_SHORT;
  569.     } else {
  570.     int              nBytes;    /* number of bytes of events available. */
  571.     KbPrivPtr      pPriv;
  572.     int              i;
  573.     
  574.     pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  575.     nBytes = read(pPriv->fd, (char *) evBuf, sizeof(evBuf));
  576.     if (nBytes >= 0) {
  577.         *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
  578.     } else if (errno == EWOULDBLOCK) {
  579.         *pNumEvents = 0;
  580.     } else {
  581.         FatalError ("Could not read the keyboard");
  582.     }
  583.     }
  584.     return (evBuf);
  585. }
  586.  
  587.  
  588. /*-
  589.  *-----------------------------------------------------------------------
  590.  * spriteKbdProcessEvent --
  591.  *    Transform a Sprite event into an X one.
  592.  *
  593.  * Results:
  594.  *    None.
  595.  *
  596.  * Side Effects:
  597.  *    An event is passed to DIX. The last VKEY_DOWN event is stored in
  598.  *    repeatEvent and repeatPhase set to REPEAT_INITIAL if we're doing
  599.  *    autorepeat and the key is to be repeated.
  600.  *
  601.  *-----------------------------------------------------------------------
  602.  */
  603. static void
  604. spriteKbdProcessEvent (pKeyboard, ev)
  605.     DevicePtr      pKeyboard;
  606.     Dev_KbdEvent  *ev;
  607. {
  608.     xEvent        xE;
  609.     register KbPrivPtr    pPriv;
  610.     register int      smask;
  611.     PtrPrivPtr          ptrPriv;
  612.  
  613.     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  614.     ptrPriv = (PtrPrivPtr) LookupPointerDevice()->devicePrivate;
  615.  
  616.     xE.u.keyButtonPointer.time = ev->time;
  617.     xE.u.keyButtonPointer.rootX = ptrPriv->x;
  618.     xE.u.keyButtonPointer.rootY = ptrPriv->y;
  619.     xE.u.u.detail = ev->key + pPriv->offset;
  620.     if (ev->keyUp) {
  621.     xE.u.u.type = KeyRelease;
  622.     if ((ev->keyUp == VKEY_UP) &&
  623.         (repeatPhase != REPEAT_NONE) &&
  624.         (repeatEvent.key == ev->key)) {
  625.         /*
  626.          * Turn off repeat if we got a real up event for the key
  627.          * being repeated
  628.          */
  629.         repeatPhase = REPEAT_NONE;
  630.     }
  631.     } else {
  632.     xE.u.u.type = KeyPress;
  633.     if ((repeatPhase != REPEAT_SHORT) &&
  634.         (pPriv->ctrl->autoRepeat ||
  635.          Bit_IsSet (xE.u.u.detail, pPriv->ctrl->autoRepeats))) {
  636.          repeatEvent = *ev;
  637.          repeatPhase = REPEAT_LONG;
  638.     }
  639.     }
  640.  
  641.     (* pKeyboard->processInputProc) (&xE, pKeyboard);
  642. }
  643.  
  644. /*-
  645.  *-----------------------------------------------------------------------
  646.  * spriteDoneEvents --
  647.  *    Nothing to do, here...
  648.  *
  649.  * Results:
  650.  *
  651.  * Side Effects:
  652.  *
  653.  *-----------------------------------------------------------------------
  654.  */
  655. static void
  656. spriteKbdDoneEvents (pKeyboard, final)
  657.     DevicePtr      pKeyboard;
  658.     Bool      final;
  659. {
  660. }
  661.  
  662. /*-
  663.  *-----------------------------------------------------------------------
  664.  * LegalModifier --
  665.  *    See if a key is legal as a modifier. We're very lenient around,
  666.  *    here, so we always return true.
  667.  *
  668.  * Results:
  669.  *    TRUE.
  670.  *
  671.  * Side Effects:
  672.  *    None.
  673.  *
  674.  *-----------------------------------------------------------------------
  675.  */
  676. Bool
  677. LegalModifier (key)
  678.     int        key;
  679. {
  680.     return (TRUE);
  681. }
  682.  
  683. /*-
  684.  *-----------------------------------------------------------------------
  685.  * spriteBlockHandler --
  686.  *    Tell the OS layer when to timeout to implement auto-repeat.
  687.  *
  688.  * Results:
  689.  *    None.
  690.  *
  691.  * Side Effects:
  692.  *    The timeout value may be overwritten.
  693.  *
  694.  *-----------------------------------------------------------------------
  695.  */
  696. void
  697. spriteBlockHandler (index, pKeyboard, ppTime, pReadMask)
  698.     int              index;        /* Screen index */
  699.     DevicePtr      pKeyboard;    /* Keyboard for which to do auto-repeat */
  700.     SpriteTime      **ppTime;     /* Pointer to timeout to use */
  701.     int              *pReadMask;    /* Mask the OS Layer will use for select. */
  702. {
  703.     if (repeatPhase == REPEAT_LONG) {
  704.     /*
  705.      * Beginning long timeout
  706.      */
  707.     repeatDelta = REPEAT_LONG_TIMEOUT;
  708.     } else if (repeatPhase == REPEAT_SHORT) {
  709.     /*
  710.      * Beginning short timeout
  711.      */
  712.     repeatDelta = REPEAT_SHORT_TIMEOUT;
  713.     } else if (repeatPhase == REPEAT_NONE) {
  714.     /*
  715.      * No repeat necessary -- it can block as long as it wants to
  716.      */
  717.     return;
  718.     } else if (repeatPhase == REPEAT_TIMEOUT) {
  719.     /*
  720.      * Interrupted timeout -- use old timeout (that was modified by
  721.      * select in the OS layer)
  722.      */
  723.     *ppTime = &repeatTimeout;
  724.     return;
  725.     }
  726.     repeatTimeout.seconds = repeatDelta / 1000;
  727.     repeatTimeout.microseconds = repeatDelta * 1000;
  728.     repeatPhase = REPEAT_TIMEOUT;
  729.     *ppTime = &repeatTimeout;
  730. }
  731.  
  732. /*-
  733.  *-----------------------------------------------------------------------
  734.  * spriteWakeupHandler --
  735.  *    Figure out if should do a repeat when the server wakes up. Because
  736.  *    select will modify repeatTimeout to contain the time left, we
  737.  *    can tell if the thing timed out.
  738.  *
  739.  * Results:
  740.  *    None.
  741.  *
  742.  * Side Effects:
  743.  *    repeatPhase may be changed to REPEAT_PENDING. If it is, *pNumReady
  744.  *    will be set to 1 and the keyboard's stream marked ready in the
  745.  *    result mask.
  746.  *
  747.  *-----------------------------------------------------------------------
  748.  */
  749. void
  750. spriteWakeupHandler (index, pKeyboard, pNumReady, pReadMask)
  751.     int              index;        /* Screen index */
  752.     DevicePtr      pKeyboard;    /* Keyboard to repeat */
  753.     int              *pNumReady;     /* Pointer to number of ready streams */
  754.     int              *pReadMask;    /* Ready streams */
  755. {
  756.     KbPrivPtr      pPriv;
  757.  
  758.     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  759.     
  760.     if ((repeatPhase == REPEAT_TIMEOUT) && (*pNumReady == 0)) {
  761.     repeatPhase = REPEAT_PENDING;
  762.     Bit_Set (pPriv->fd, pReadMask);
  763.     *pNumReady = 1;
  764.     }
  765. }
  766. @
  767.  
  768.  
  769. 5.3
  770. log
  771. @Latest changs from Adam for auto-repeat.
  772. @
  773. text
  774. @d19 1
  775. a19 1
  776.     "$Header: spriteKbd.c,v 5.2 88/09/15 16:31:16 ouster Exp $ SPRITE (Berkeley)";
  777. d358 3
  778. a360 1
  779.          * Reset keyboard to avoid spurious events
  780. a361 1
  781.         (void) write(fd, &reset, 1);
  782. d375 5
  783. @
  784.  
  785.  
  786. 5.2
  787. log
  788. @Changes to get running under new C library.
  789. @
  790. text
  791. @d19 1
  792. a19 1
  793.     "$Header: spriteKbd.c,v 5.1 88/03/27 21:17:17 deboor Exp $ SPRITE (Berkeley)";
  794. d68 1
  795. a68 1
  796. }                  repeatPhase;
  797. d303 1
  798. d365 4
  799. @
  800.  
  801.  
  802. 5.1
  803. log
  804. @*** empty log message ***
  805. @
  806. text
  807. @d19 1
  808. a19 1
  809.     "$Header: spriteKbd.c,v 5.0 87/09/11 11:26:12 deboor Exp $ SPRITE (Berkeley)";
  810. d22 4
  811. a28 2
  812. #define Time SpriteTime
  813. #include    <fs.h>
  814. a29 1
  815. #undef Time
  816. d31 5
  817. d44 9
  818. a302 1
  819.     int              tmp;
  820. d305 1
  821. d321 8
  822. a328 4
  823.         if (Fs_Open("/dev/Xevent", FS_READ|FS_WRITE|FS_NON_BLOCKING, 0,
  824.                  &sysKbPriv.fd) != SUCCESS) {
  825.                  Error ("Opening /dev/Xevent");
  826.                  return (!Success);
  827. d355 5
  828. d392 3
  829. a394 4
  830.     KbPrivPtr      pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  831.     char          kbdCmd;
  832.     int              junk;
  833.     SpriteTime      sleepTime;
  834. d400 8
  835. a407 8
  836.     kbdCmd = '\2';
  837.     (void)Fs_Write(pPriv->fd, 1, &kbdCmd, &junk);
  838.     
  839.     sleepTime.microseconds = pPriv->ctrl->bell_duration * 1000;
  840.     sleepTime.seconds = 0;
  841.     while (sleepTime.microseconds >= 1000000) {
  842.     sleepTime.seconds += 1;
  843.     sleepTime.microseconds -= 1000000;
  844. d409 1
  845. a409 1
  846.     (void)Sync_WaitTime(sleepTime);
  847. d411 2
  848. a412 2
  849.     kbdCmd = '\3';
  850.     (void)Fs_Write(pPriv->fd, 1, &kbdCmd, &junk);
  851. d434 1
  852. a434 3
  853.     int              junk;
  854.     static char      KBD_CLICK_ON = '\12';
  855.     static char      KBD_CLICK_OFF = '\13';
  856. d440 1
  857. a440 1
  858.     (void)Fs_Write(pPriv->fd, 1, &KBD_CLICK_ON, &junk);
  859. d442 1
  860. a442 1
  861.     (void)Fs_Write(pPriv->fd, 1, &KBD_CLICK_OFF, &junk);
  862. d445 2
  863. d494 7
  864. a500 9
  865.     switch (Fs_Read (pPriv->fd, sizeof(evBuf), evBuf, &nBytes)) {
  866.         case SUCCESS:
  867.         *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
  868.         break;
  869.         case FS_WOULD_BLOCK:
  870.         *pNumEvents = 0;
  871.         break;
  872.         default:
  873.         FatalError ("Could not read the keyboard");
  874. d640 1
  875. a640 1
  876.      * Fs_Select in the OS layer)
  877. d655 1
  878. a655 1
  879.  *    Fs_Select will modify repeatTimeout to contain the time left, we
  880. @
  881.  
  882.  
  883. 5.0
  884. log
  885. @beta 4 release
  886. @
  887. text
  888. @a15 2
  889.  * TODO:
  890.  *    Nuke strings on the various function keys (arrow/alternate)
  891. d19 1
  892. a19 1
  893.     "$Header: spriteKbd.c,v 1.5 87/08/21 20:35:02 deboor Exp $ SPRITE (Berkeley)";
  894. d24 1
  895. d27 1
  896. d32 3
  897. a34 2
  898. #define VKEY_UP      0x80
  899. #define VKEY_DOWN 0
  900. d36 2
  901. d44 10
  902. d55 6
  903. d68 2
  904. d79 1
  905. a79 1
  906.  
  907. d82 8
  908. a92 2
  909. #define    XK_L3    XK_Menu
  910. #define    XK_L4    XK_Undo
  911. a95 2
  912. #define    XK_L5    XK_Insert
  913. #define    XK_L6    XK_Select
  914. a98 2
  915. #define    XK_L7    XK_Execute
  916. #define    XK_L8    XK_Print
  917. a101 2
  918. #define    XK_L9    XK_Find
  919. #define    XK_L10    XK_Help
  920. d105 1
  921. a106 1
  922.  
  923. a236 5
  924. static ModifierMapRec sunModMap = {
  925. /*  lock shfta shftb ctrla ctrlb   m1a   m1b m2a m2b m3a m3b m4a m4b m5a m5b */
  926.     0x77, 0x63, 0x6e, 0x4c,    0, 0x78, 0x7a,  0,  0,  0,  0,  0,  0,  0,  0,
  927. };
  928.  
  929. d242 24
  930. d275 1
  931. a276 1
  932.  *     Need to nuke strings for arrow keys! (and Alternate key?)
  933. d279 1
  934. d281 1
  935. a281 1
  936. spriteKbdProc (pKeyboard, what)
  937. d284 2
  938. d306 1
  939. a306 1
  940.         if (Fs_Open ("/dev/Xevent", FS_READ | FS_NON_BLOCKING, 0,
  941. d322 13
  942. a334 1
  943.         InitKeyboardDeviceStruct(pKeyboard, &sunMapDesc, &sunModMap,
  944. d368 22
  945. a389 1
  946.     /* no can do, for now */
  947. d406 1
  948. a406 1
  949. spriteKbdCtrl (pKeyboard)
  950. d408 1
  951. d410 17
  952. a426 1
  953.     /* can only change key click on sprite 3 keyboards, so what's the use? */
  954. d447 1
  955. a447 3
  956.     int              nBytes;        /* number of bytes of events available. */
  957.     KbPrivPtr      pPriv;
  958.     static Dev_KbdEvent    evBuf[MAXEVENTS];   /* Buffer for Firm_events */
  959. d449 32
  960. a480 10
  961.     pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  962.     switch (Fs_Read (pPriv->fd, sizeof(evBuf), evBuf, &nBytes)) {
  963.     case SUCCESS:
  964.         *pNumEvents = nBytes / sizeof (Dev_KbdEvent);
  965.         break;
  966.     case FS_WOULD_BLOCK:
  967.         *pNumEvents = 0;
  968.         break;
  969.     default:
  970.         FatalError ("Could not read the keyboard");
  971. d489 1
  972. d492 1
  973. d495 3
  974. a498 13
  975.  *    Sometimes extra events will be passed to ProcessInput b/c the
  976.  *    state of the keyboard modifier keys is different for certain
  977.  *    keys on a sprite than on a microvax. e.g. typing '<' will cause
  978.  *    a KEY_SHIFT to be sent to dix earlier, but on a microvax, it should
  979.  *    only generate a KEY_LANGLE_RANGLE code, so an up event on KEY_SHIFT,
  980.  *    a down event on KEY_LANGLE_RANGLE and a down event on KEY_SHIFT
  981.  *    will be generated. Well, at least it's a standard...
  982.  *    A nicer approach would be to play with the KeyButtonMask variable
  983.  *    in dix, but that is forbidden...
  984.  *
  985.  * Note:
  986.  *    Since alpha1, DDXEventRec has gone away and we now directly translate
  987.  *    into Xevent.  Therefore, much of this code was rewritten.
  988. d517 21
  989. a537 2
  990.     xE.u.u.type = (ev->keyUp ? KeyRelease : KeyPress);
  991.     xE.u.u.detail = ev->key;
  992. d579 84
  993. @
  994.  
  995.  
  996. 1.5
  997. log
  998. @Nuked the sun-originated keysyms for the weird function keys (left and right)
  999. @
  1000. text
  1001. @d21 1
  1002. a21 1
  1003.     "$Header: spriteKbd.c,v 1.4 87/06/20 19:56:46 deboor Exp $ SPRITE (Berkeley)";
  1004. d59 2
  1005. a60 2
  1006. #define    XK_L1    NoSymbol
  1007. #define    XK_L2    NoSymbol
  1008. d64 2
  1009. a65 2
  1010. #define    XK_L3    NoSymbol
  1011. #define    XK_L4    NoSymbol
  1012. d69 2
  1013. a70 2
  1014. #define    XK_L5    NoSymbol
  1015. #define    XK_L6    NoSymbol
  1016. d72 1
  1017. a72 1
  1018. #define    XK_R8    NoSymbol
  1019. d74 7
  1020. a80 7
  1021. #define    XK_L7    NoSymbol
  1022. #define    XK_L8    NoSymbol
  1023. #define    XK_R10    NoSymbol
  1024. #define    XK_R11    NoSymbol
  1025. #define    XK_R12    NoSymbol
  1026. #define    XK_L9    NoSymbol
  1027. #define    XK_L10    NoSymbol
  1028. d82 1
  1029. a82 1
  1030. #define    XK_R14    NoSymbol
  1031. @
  1032.  
  1033.  
  1034. 1.4
  1035. log
  1036. @adapted to Beta-0
  1037. @
  1038. text
  1039. @d21 1
  1040. a21 1
  1041.     "$Header: spriteKbd.c,v 1.3 87/06/17 17:18:20 deboor Exp $ SPRITE (Berkeley)";
  1042. d52 32
  1043. @
  1044.  
  1045.  
  1046. 1.3
  1047. log
  1048. @Fixed problem with definition of VKEY_UP. the kernel gives
  1049. back 0x80, not TRUE (ie. 1)
  1050. @
  1051. text
  1052. @d21 1
  1053. a21 1
  1054.     "$Header: spriteKbd.c,v 1.2 87/06/17 16:16:21 deboor Exp $ SPRITE (Berkeley)";
  1055. d30 1
  1056. a30 5
  1057. typedef struct {
  1058.     int              trans;              /* Original translation form */
  1059.     int              smask;              /* State of shift modifiers */
  1060.     int              ksmask;             /* State of individual modifier keys */
  1061. } SunKbPrivRec, *SunKbPrivPtr;
  1062. a31 2
  1063. #include    "keynames.h"
  1064.  
  1065. a41 1
  1066. static SunKbPrivRec    spriteKbPriv;  
  1067. d49 1
  1068. a49 1
  1069.     (pointer)&spriteKbPriv,    /* Private to keyboard device */
  1070. a51 10
  1071. /*
  1072.  * Constants for the ksmask field of the private data
  1073.  */
  1074. #define    SunLeftShiftMask    (1<<0)
  1075. #define SunRightShiftMask       (1<<1)
  1076. #define SunCtrlMask            (1<<2)
  1077. #define SunLeftMetaMask        (1<<3)
  1078. #define SunRightMetaMask        (1<<4)
  1079. #define SunCapsLockMask            (1<<5)
  1080. #define SunLockMask            (1<<6)
  1081. d54 129
  1082. a182 13
  1083. /*
  1084.  * The X window system expects key values to have the same values
  1085.  * as generated by the DEC LK201 keyboard.  An array 
  1086.  * is used to convert Sun raw key codes into the LK201 codes.
  1087.  *
  1088.  * Raw key codes that do not correspond to real keys are UNBOUND.
  1089.  *
  1090.  * Sun-{2,3} keyboard to LK201, shifted and unshifted.
  1091.  *
  1092.  * L1-L10 are the left function keys.
  1093.  * T1-T10 are the top function keys.
  1094.  * R1-R15 are the right function keys.
  1095.  */
  1096. d184 4
  1097. a187 5
  1098. #define UNBOUND 0377
  1099. #define KEY_LEFTSHIFT    99
  1100. #define KEY_RIGHTSHIFT    110
  1101. #define KEY_LEFTMETA    120
  1102. #define KEY_RIGHTMETA    122
  1103. d189 3
  1104. a191 66
  1105.  
  1106. static unsigned char sunToLK201Map[] = {
  1107. /*   0 */ UNBOUND,                   UNBOUND,     /* L1 */    
  1108. /*   2 */ UNBOUND,              UNBOUND,     /* L2 */
  1109. /*   4 */ UNBOUND,            KEY_F1,     /* T1 */    
  1110. /*   6 */ KEY_F2,     /* T2 */    UNBOUND,
  1111. /*   8 */ KEY_F3,     /* T3 */    UNBOUND,        
  1112. /*  10 */ KEY_F4,     /* T4 */    UNBOUND, 
  1113. /*  12 */ KEY_F5,     /* T5 */    UNBOUND,        
  1114. /*  14 */ KEY_F6,     /* T6 */    UNBOUND,
  1115. /*  16 */ KEY_F7,     /* T7 */    KEY_F8,     /* T8 */    
  1116. /*  18 */ KEY_F9,     /* T9 */    KEY_F10,     /* T10 */ 
  1117. /*  20 */ UNBOUND,            UNBOUND,     /* R1 */    
  1118. /*  22 */ UNBOUND,     /* R2 */    UNBOUND,     /* R3 */
  1119. /*  24 */ UNBOUND,            UNBOUND,     /* L3 */    
  1120. /*  26 */ UNBOUND,     /* L4 */    UNBOUND, 
  1121. /*  28 */ UNBOUND,            KEY_ESC,     /* ESC*/    
  1122. /*  30 */ KEY_TR_1,     /* 1 */        KEY_TR_2,     /* 2 */
  1123. /*  32 */ KEY_TR_3,     /* 3 */        KEY_TR_4,     /* 4 */    
  1124. /*  34 */ KEY_TR_5,     /* 5 */        KEY_TR_6,     /* 6 */
  1125. /*  36 */ KEY_TR_7,     /* 7 */        KEY_TR_8,     /* 8 */    
  1126. /*  38 */ KEY_TR_9,     /* 9 */        KEY_TR_0,     /* 0 */
  1127. /*  40 */ KEY_UBAR,     /* - */        KEY_PLUS,     /* = */    
  1128. /*  42 */ KEY_TILDE,     /* ` */        KEY_BS,     /* BS */
  1129. /*  44 */ UNBOUND,                  UNBOUND,     /* R4 */   
  1130. /*  46 */ UNBOUND,      /* R5 */    UNBOUND,     /* R6 */
  1131. /*  48 */ UNBOUND,                  UNBOUND,     /* L5 */   
  1132. /*  50 */ UNBOUND,                  UNBOUND,     /* L6 */
  1133. /*  52 */ UNBOUND,                  KEY_TAB,     /* tab */  
  1134. /*  54 */ KEY_Q,        /* q */     KEY_W,      /* w */
  1135. /*  56 */ KEY_E,        /* e */     KEY_R,      /* r */  
  1136. /*  58 */ KEY_T,        /* t */     KEY_Y,      /* y */
  1137. /*  60 */ KEY_U,        /* u */     KEY_I,      /* i */  
  1138. /*  62 */ KEY_O,        /* o */     KEY_P,      /* p */
  1139. /*  64 */ KEY_LBRACE,   /* [ */     KEY_RBRACE, /* ] */
  1140. /*  66 */ KEY_DELETE,   /* del */   UNBOUND,
  1141. /*  68 */ UNBOUND,                KEY_UP,     /* R8 */ 
  1142. /*  70 */ UNBOUND,      /* R9 */    UNBOUND,
  1143. /*  72 */ UNBOUND,      /* L7 */    UNBOUND,     /* L8 */       
  1144. /*  74 */ UNBOUND,                  UNBOUND, 
  1145. /*  76 */ KEY_CTRL,     /* ctl */   KEY_A,      /* a */  
  1146. /*  78 */ KEY_S,        /* s */     KEY_D,      /* d */
  1147. /*  80 */ KEY_F,        /* f */     KEY_G,      /* g */  
  1148. /*  82 */ KEY_H,        /* h */     KEY_J,      /* j */ 
  1149. /*  84 */ KEY_K,        /* k */     KEY_L,      /* l */  
  1150. /*  86 */ KEY_SEMICOLON,/* ; */     KEY_QUOTE,     /* ' */
  1151. /*  88 */ KEY_VBAR,     /* \ */     KEY_RETURN, /* ret */   
  1152. /*  90 */ UNBOUND,                  KEY_LEFT,     /* R10 */
  1153. /*  92 */ UNBOUND,      /* R11 */   KEY_RIGHT,     /* R12 */  
  1154. /*  94 */ UNBOUND,                  UNBOUND,     /* L9 */
  1155. /*  96 */ UNBOUND,                  KEY_LOCK,     /* L10 */     
  1156. /*  98 */ UNBOUND,                  KEY_LEFTSHIFT,
  1157. /* 100 */ KEY_Z,        /* z */     KEY_X,      /* x */  
  1158. /* 102 */ KEY_C,        /* c */     KEY_V,      /* v */
  1159. /* 104 */ KEY_B,        /* b */     KEY_N,      /* n */  
  1160. /* 106 */ KEY_M,        /* m */     KEY_COMMA,     /* , */
  1161. /* 108 */ KEY_PERIOD,   /* . */     KEY_QMARK,     /* / */   
  1162. /* 110 */ KEY_RIGHTSHIFT,              KEY_LF,     /* lf */
  1163. /* 112 */ UNBOUND,      /* R13 */   KEY_DOWN,     /* R14 */     
  1164. /* 114 */ UNBOUND,      /* R15 */   UNBOUND, 
  1165. /* 116 */ UNBOUND,                  UNBOUND,                
  1166. /* 118 */ UNBOUND,                  KEY_LOCK,     /* caps*/
  1167. /* 120 */ KEY_LEFTMETA, /* left */  KEY_SPACE,     /* sp */     
  1168. /* 122 */ KEY_RIGHTMETA,/* right */ UNBOUND, 
  1169. /* 124 */ UNBOUND,                  UNBOUND,                
  1170. /* 126 */ UNBOUND,                  UNBOUND,
  1171. a243 6
  1172.         spriteKbPriv.ksmask = spriteKbPriv.smask = 0;
  1173.  
  1174.         pKeyboard->deviceID = MakeDevice(DEVICE_KEYBOARD,
  1175.                        SUN_SUN2,
  1176.                        M_SUN,
  1177.                        0);
  1178. a245 2
  1179.         spriteInitKbdMappings (map);
  1180.  
  1181. d247 2
  1182. a248 3
  1183.         InitKeyboardDeviceStruct(
  1184.             pKeyboard, map, MAP_LENGTH - 1, spriteBell,
  1185.             spriteKbdCtrl);
  1186. a339 73
  1187.     
  1188. /*-
  1189.  *-----------------------------------------------------------------------
  1190.  * spriteKbdPair --
  1191.  *    Used for pairs of modifier keys which map to a single X keycode.
  1192.  *    Make sure that the state of the single keycode reflects the
  1193.  *    state of the two real keys. I.e. if one is down and the other
  1194.  *    is pressed, don't send a KeyPressed event. etc.
  1195.  *
  1196.  * Results:
  1197.  *    Returns TRUE if the event should be given to DIX and FALSE if it should
  1198.  *    be discarded.
  1199.  *
  1200.  * Side Effects:
  1201.  *      The smask and ksmask fields of the private data are altered.
  1202.  *
  1203.  *-----------------------------------------------------------------------
  1204.  */
  1205. static Bool
  1206. spriteKbdPair (pPriv, keyMask, pairMask, xKeyMask, state)
  1207.     SunKbPrivPtr  pPriv;        /* Private data for affected keyboard */
  1208.     int              keyMask;      /* Sun*Mask for key stroke */
  1209.     int              pairMask;     /* Sun*Mask for paired modifier key */
  1210.     int              xKeyMask;     /* Mask for equivalent X key */
  1211.     int              state;        /* State of the key in keyMask */
  1212. {
  1213.     if (pPriv->smask & xKeyMask) {
  1214.     /*
  1215.      * Virtual key is already down. If this thing is the last of the
  1216.      * pair to go up, then the up event should be sent and we update
  1217.      * the smask to reflect the virtual key's new state.
  1218.      * If, however, this is the second of the pair to go down,
  1219.      * nothing should be sent and we merely record that the key
  1220.      * is down...
  1221.      */
  1222.     if (state == VKEY_UP) {
  1223.         pPriv->ksmask &= ~keyMask;
  1224.         if ((pPriv->ksmask & pairMask) == 0) {
  1225.         pPriv->smask &= ~xKeyMask;
  1226.         return TRUE;
  1227.         } else {
  1228.         return FALSE;
  1229.         }
  1230.     } else {
  1231.         pPriv->ksmask |= keyMask;
  1232.         if ((pPriv->ksmask & pairMask) == 0) {
  1233.         /*
  1234.          * This should never happen...
  1235.          */
  1236.         ErrorF("spriteKbdPair: xKey %x down but pair isn't\n", xKeyMask);
  1237.         }
  1238.         return FALSE;
  1239.     }
  1240.     } else {
  1241.     /*
  1242.      * If the virtual key is up, all this can really be is a down event
  1243.      * for one of the pair. We check just for debugging purposes.
  1244.      * For a down event, nothing special happens, the event is just
  1245.      * recorded in the private data.
  1246.      */
  1247.     if (state == VKEY_UP) {
  1248.         /*
  1249.          * This should never happen...
  1250.          */
  1251.         ErrorF("spriteKbdPair: xKey %x up when VKEY_UP received\n", xKeyMask);
  1252.         return FALSE;
  1253.     } else {
  1254.         pPriv->smask |= xKeyMask;
  1255.         pPriv->ksmask |= keyMask;
  1256.         return TRUE;
  1257.     }
  1258.     }
  1259. }
  1260. a370 1
  1261.     register SunKbPrivPtr pSunPriv;
  1262. a374 1
  1263.     pSunPriv = (SunKbPrivPtr) pPriv->devPrivate;
  1264. d380 2
  1265. a381 1
  1266.     xE.type = (ev->keyUp ? KeyRelease : KeyPress);
  1267. a382 31
  1268.     xE.detail = sunToLK201Map[ev->key];
  1269.     switch (xE.detail) {
  1270.     case KEY_LEFTMETA:
  1271.         if (!spriteKbdPair (pSunPriv, SunLeftMetaMask, SunRightMetaMask,
  1272.                 Mod1Mask, ev->keyUp)) {
  1273.                     return;
  1274.         }
  1275.         xE.detail = KEY_META;
  1276.         break;
  1277.     case KEY_RIGHTMETA:
  1278.         if (!spriteKbdPair (pSunPriv, SunRightMetaMask, SunLeftMetaMask,
  1279.                 Mod1Mask, ev->keyUp)) {
  1280.                     return;
  1281.         }
  1282.         xE.detail = KEY_META;
  1283.         break;
  1284.     case KEY_LEFTSHIFT:            /* Left-hand "Shift" key */
  1285.         if (!spriteKbdPair (pSunPriv, SunLeftShiftMask, SunRightShiftMask,
  1286.                 ShiftMask, ev->keyUp)) {
  1287.                     return;
  1288.         }
  1289.         xE.detail = KEY_SHIFT;
  1290.         break;
  1291.     case KEY_RIGHTSHIFT:            /* Right-hand "Shift" key */
  1292.         if (!spriteKbdPair (pSunPriv, SunRightShiftMask, SunLeftShiftMask,
  1293.                 ShiftMask, ev->keyUp)) {
  1294.                     return;
  1295.         }
  1296.         xE.detail = KEY_SHIFT;
  1297.         break;
  1298.     }
  1299. d403 1
  1300. a403 1
  1301.  
  1302. d406 3
  1303. a408 2
  1304.  * spriteInitKbdMappings
  1305.  *    Initialize mappings.  This is a bit wasteful...
  1306. d411 1
  1307. d414 1
  1308. d418 3
  1309. a420 2
  1310. spriteInitKbdMappings(map)
  1311.     BYTE    *map;
  1312. d422 1
  1313. a422 14
  1314.     int i;
  1315.  
  1316.     bzero (map, MAP_LENGTH);
  1317.     for (i = 0; i < sizeof(sunToLK201Map)/sizeof(sunToLK201Map[0]); i++) {
  1318.     if (sunToLK201Map[i] != UNBOUND) {
  1319.         map[sunToLK201Map[i]] = sunToLK201Map[i];
  1320.     }
  1321.     }
  1322.  
  1323.     map[1] = KEY_META;
  1324.     map[KEY_SHIFT] = KEY_SHIFT;
  1325.     map[KEY_LOCK] = KEY_LOCK;
  1326.     map[KEY_CTRL] = KEY_CTRL;
  1327.     /* More meta keys...? */
  1328. @
  1329.  
  1330.  
  1331. 1.2
  1332. log
  1333. @Dropped a line in the map during translation...
  1334. @
  1335. text
  1336. @d21 1
  1337. a21 1
  1338.     "$Header: spriteKbd.c,v 1.1 87/06/16 12:21:13 deboor Exp $ SPRITE (Berkeley)";
  1339. d38 1
  1340. a38 1
  1341. #define VKEY_UP      1
  1342. @
  1343.  
  1344.  
  1345. 1.1
  1346. log
  1347. @Initial revision
  1348. @
  1349. text
  1350. @d21 1
  1351. a21 1
  1352.     "$Header: spriteKbd.c,v 2.7 87/05/28 21:49:46 deboor Exp $ SPRITE (Berkeley)";
  1353. d126 2
  1354. a127 1
  1355. /*  66 */ KEY_DELETE,   /* del */   KEY_UP,     /* R8 */ 
  1356. @
  1357.